﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;

public partial class Form1 : Form
{
    private List<(string English, string Chinese)> _words;
    private int _currentIndex = 0;
    private WordService _wordService;

    public Form1()
    {
        InitializeComponent();
        InitializeApp();
    }

    // 初始化应用程序
    private void InitializeApp()
    {
        _wordService = new WordService();
        _words = _wordService.GetAllWords();
        ShowNextWord();
    }

    // 显示下一个单词
    private void ShowNextWord()
    {
        if (_currentIndex < _words.Count)
        {
            lblChinese.Text = _words[_currentIndex].Chinese;
            txtInput.Clear();
            lblResult.Text = "";
            txtInput.Focus();
        }
        else
        {
            lblChinese.Text = "所有单词已完成！";
            txtInput.Enabled = false;
            btnShowHint.Enabled = false; // 禁用按钮
        }
    }

    // 检查用户输入
    private void CheckAnswer()
    {
        string userInput = txtInput.Text.Trim().ToLower();
        string correctAnswer = _words[_currentIndex].English.ToLower();

        if (userInput == correctAnswer)
        {
            lblResult.Text = "✅ 正确！";
            _currentIndex++;
            ShowNextWord();
        }
        else
        {
            lblResult.Text = "❌ 错误！正确答案是：" + _words[_currentIndex].English;
            txtInput.Clear();
        }
    }
    // 新增方法：显示当前单词的英文和中文
    private void btnShowHint_Click(object sender, EventArgs e)
    {
        if (_currentIndex < _words.Count)
        {
            string english = _words[_currentIndex].English;
            string chinese = _words[_currentIndex].Chinese;
            MessageBox.Show($"英文：{english}\n中文：{chinese}", "单词示意", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        else
        {
            MessageBox.Show("没有更多单词了！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }
    }
    // 文本框回车事件
    private void txtInput_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (e.KeyChar == (char)Keys.Enter)
        {
            CheckAnswer();
            e.Handled = true; // 阻止默认回车行为
        }
    }
}